package com.example.huangyuanquan

import android.R
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity


class AddStudentActivity : AppCompatActivity() {
    private var editTextStudentId: EditText? = null
    private var editTextStudentName: EditText? = null
    private var editTextStudentGender: EditText? = null
    private var editTextStudentClass: EditText? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_add_student)
        editTextStudentId = findViewById<EditText>(R.id.editTextStudentId)
        editTextStudentName = findViewById<EditText>(R.id.editTextStudentName)
        editTextStudentGender = findViewById<EditText>(R.id.editTextStudentGender)
        editTextStudentClass = findViewById<EditText>(R.id.editTextStudentClass)

                findViewById<View>(R.id.buttonSave).setOnClickListener { view: View? ->
                    val student = Student(
                editTextStudentId.getText().toString(),
                editTextStudentName.getText().toString(),
                editTextStudentGender.getText().toString(),
                editTextStudentClass.getText().toString()
            )
            val returnIntent = Intent()
            returnIntent.putExtra("new_student", student)
            setResult(RESULT_OK, returnIntent)
            finish()
        }

        findViewById<View>(R.id.buttonCancel).setOnClickListener { view: View? -> finish() }
    }
}